package com.kukudexin;

/**
 * @author: 酷酷的鑫
 * @Date: 2021/12/8 18:00
 * @description:
 */
public class Test17 {

    public static void main(String[] args) {
        GenericSon<Integer, Double> obj = new GenericSon<>(Integer.valueOf(123), Double.valueOf("3.14"));
        //创建子类对象,使用Integer替换T参数, 使用Double替换V参数, 同时把T参数的Integer类型传递给父类

        Integer val = obj.getVal();
        Double val2 = obj.getVal2();
    }
    //定义泛型类作为父类
    static class GenericFather<T>{
        private  T val;

        public GenericFather(T val) {
            this.val = val;
        }

        public T getVal() {
            return val;
        }
    }
    //定义泛型子类,继承泛型父类, 在泛型子类中可以添加自己的类型参数
    static class GenericSon <T,V>  extends GenericFather<T>{
        private  V val2;

        public GenericSon(T val, V val2) {
            super(val);
            this.val2 = val2;
        }

        public V getVal2() {
            return val2;
        }
    }
}
